#include <iostream>

using namespace std;


int findMin(int arr[], int size);

enum Poker{A = 1, J = 11, Q, K, X = 54};

/*bool isStraight(int arr[], int length){
	if(length < 5)
		return false;

	int *temp = new int[length];
	memset(temp, 0, sizeof(arr[0]) * length );
	
	int jokerCount = 0;
	int index = 0;

	for(int i = 0; i < length; ++i){
		index = arr[i] % length;
		// Not the joker, X stands for the Joker
		if(Poker::X != arr[i]){
			// Duplicate, or the distance between this car and another is over the length
			if(0 != temp[index])
				return false;
			else{
				temp[index] = arr[i];
			}
		}
		else{
			++jokerCount;
		}
	}
	// A cannot adjacent with 2
	// if(Poker::A == temp[0] && 2 == temp[1])
	// 	return false;
	//

	if(jokerCount > 2)
		return false;

	index = 0;
	for(; index  < length || jokerCount >= 0; ++index){
		if(0 == temp[index]){
			--jokerCount;
		}
	}

	if(index < length)
		return false;
	return true;
}*/

bool isStraight(int arr[], int length){
	if(length < 5)
		return false;

	int *temp = new int[length];
	memset(temp, 0, sizeof(arr[0]) * length );
	
	int jokerCount = 0;
	int index = 0;
	int min = findMin(arr, length);

	for(int i = 0; i < length; ++i){
		index = arr[i] - min;

		// Not the joker, X stands for the Joker
		if(Poker::X != arr[i]){
			if(index >= length)
				return false;
			// Duplicate, or the distance between this car and another is over the length
			if(0 != temp[index])
				return false;
			else{
				temp[index] = arr[i];
			}
		}
		else{
			++jokerCount;
		}
	}

	if(jokerCount > 2)
		return false;

	 // A cannot adjacent with 2
	if(Poker::A == temp[0] && Poker::K != temp[length - 1])
	 	return false;	

	index = 0;
	for(; index  < length || jokerCount >= 0; ++index){
		if(0 == temp[index]){
			--jokerCount;
		}
	}

	if(index < length)
		return false;
	return true;
}

int findMin(int arr[], int size){
	int minIndex = 0;
	for(int i = 1; i < size; ++i)
		if(arr[minIndex] > arr[i])
			minIndex = i;

	return arr[minIndex];
}

int pmain(){

	// int arr[5] = {2, 3, 5, 6, Poker::X};
	// int arr[5] = {1, 2, 3, 4, Poker::X};
	int arr[5] = {A, J, Q, K, Poker::X};

	bool b = isStraight(arr, sizeof(arr) / sizeof(arr[0]));

	return 0;
}